package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：预警阈值键值转换
 * @Date：Create by 2023-12-04 14:51:04
 */
public interface IEarlyWarningThresholdFilter {

	String JUDGE_RULE = "judgeRule" ;
	String THRESHOLD_LEVEL = "thresholdLevel" ;

	String EARLY_WARNING_THRESHOLD_JUDGE_RULE = "ecp-admin.earlyWarningThreshold.judgeRule" ;
	String EARLY_WARNING_THRESHOLD_THRESHOLD_LEVEL = "ecp-admin.earlyWarningThreshold.thresholdLevel" ;

	class EarlyWarningThresholdExportFilter implements ValueFilter {

		private Map<String, String> judgeRuleMap;
		private Map<String, String> thresholdLevelMap;

		public EarlyWarningThresholdExportFilter() {
			judgeRuleMap = DictHelper.i().stringVlMap(EARLY_WARNING_THRESHOLD_JUDGE_RULE);
			thresholdLevelMap = DictHelper.i().stringVlMap(EARLY_WARNING_THRESHOLD_THRESHOLD_LEVEL);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, JUDGE_RULE)) {
				return CommonUtils.orElse(judgeRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, THRESHOLD_LEVEL)) {
				return CommonUtils.orElse(thresholdLevelMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class EarlyWarningThresholdUploadFilter implements ValueFilter {

		private Map<String, String> judgeRuleMap;
		private Map<String, String> thresholdLevelMap;

		public EarlyWarningThresholdUploadFilter() {
			judgeRuleMap = DictHelper.i().stringLvMap(EARLY_WARNING_THRESHOLD_JUDGE_RULE);
			thresholdLevelMap = DictHelper.i().stringLvMap(EARLY_WARNING_THRESHOLD_THRESHOLD_LEVEL);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, JUDGE_RULE)) {
				return CommonUtils.orElse(judgeRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, THRESHOLD_LEVEL)) {
				return CommonUtils.orElse(thresholdLevelMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}
